******************************************************************************
*                                                                            *
* Alexander B. Downes and Todd S. Sechser                                    *
* "The Illusion of Democratic Credibility"                                   *
* International Organization 66:3 (2012): 457-81                             *
*                                                                            *
******************************************************************************


* Purpose
* This is a Stata replication file for "The Illusion of Democratic Credibility." In the article (pp. 467-70), we attempted to replicate the analysis of Militarized Interstate Dispute (MID) reciprocation conducted in Kenneth A. Schultz's book Democracy and Coercive Diplomacy (2001) in order to identify the 25 most influential democratic victories in his analysis.  Unfortunately, we were unable to obtain the original dataset from the author, so instead we re-created the dataset by following the procedures described in the book (see Schultz 2001, pp. 125-31, 141-44, and 261-72).  This file performs these operations, creating a dataset file titled "Downes-Sechser-Appendix-B.dta" (also included with this replication file).  Page references below refer to Schultz (2001).
*
* Location
* This command file and associated datasets can be downloaded from <http://dvn.iq.harvard.edu/dvn/dv/tsechser>.
* 
* Requirements
* 1. This file requires the "ldfbeta" Stata package.  It can be installed by typing "net install ldfbeta, from(http://www.ats.ucla.edu/stat/stata/ado/analysis)" (without quotes) into the Stata command window.  The original article used Intercooled Stata 10.1.  This file also requires several component datasets, from which the final dataset is built.  These datasets are also available from <http://dvn.iq.harvard.edu/dvn/dv/tsechser>.
* 2. This file requires nine component datasets, which can be downloaded from <http://dvn.iq.harvard.edu/dvn/dv/tsechser>.
*
* Erratum
* Table 2 in "The Illusion of Democratic Credibility" (p. 469) incorrectly lists the year for MID #3416 (Israel-Syria) as 1952.  The correct year is 1955.
*
* Version
* Last updated: August 20, 2012



clear
set more off
di "How much memory would you like to allocate to Stata? " _request(mem)
set mem $mem
*Set directory
di "Please type the pathway for the folder containing the datasets to be merged: " _request(dir)
cd $dir


***CREATE DATASET OF BILATERAL MIDS, 1816-1992 (Schultz 2001, pp. 125-6)

*Use MID v.2.1
*Unit of analysis = MID
insheet using MIDA_210.csv

*Drop multilateral MIDs
*Sidea and Sideb indicate number of participants on each side
drop if sidea+sideb>2
gen year = startyear
sort idnumber
*Codebook for MID 2.1 says: "Reciprocated dispute (-1 = yes, 0 = no)"; change this so that reciprocated = 1
replace recip = recip*(-1)
label var recip "Reciprocation indicator from MID"
save MIDA_210.dta, replace
clear

*Unit of analysis = MID participant
insheet using MIDB_210.csv

*Incorporate initiators first
drop if sidea==0

*Drop non-originators (Schultz 2001, p. 263: "restricted to original dyads")
drop if orig == 0
sort idnumber
save MIDB_210.dta, replace

use MIDA_210.dta, clear
gen keepobs = 1
merge idnumber using MIDB_210.dta, keep(statenum revtype)

*Drop observations not associated with bilateral MIDs
drop if keepobs ~= 1
drop _merge
rename statenum ccode_a
sort idnumber
save MIDA_210.dta, replace
clear

insheet using MIDB_210.csv

*Incorporate targets
drop if sidea==1

*Drop non-originators (Schultz 2001, p. 263: "restricted to original dyads")
drop if orig == 0

*Generate reciprocation measure using hostility levels: reciphost = 1 if hostlev of target > 1 (Schultz 2001, p. 263)
gen reciphost = 0
replace reciphost = 1 if hostlev > 1
label var reciphost "Alternative reciprocation indicator: 1 if hostlev > 1"
rename hostlev hostlev_b
sort idnumber
save MIDB_210.dta, replace

use MIDA_210.dta, clear
merge idnumber using MIDB_210.dta, keep(statenum reciphost hostlev_b)
drop if keepobs ~= 1
drop _merge
rename statenum ccode_b

replace startday = . if startday==-9
replace endday = . if endday==-9
keep idnumber year ccode_a ccode_b revtype recip* hostlev_b keepobs start* end*
save Downes-Sechser-Appendix-B.dta, replace


***MERGE WITH STATE NAMES

clear
insheet using states2008.1.csv
rename stateabb cabb_a
rename ccode ccode_a
rename statenme cname_a
sort ccode_a
save states2008.1.dta, replace

use Downes-Sechser-Appendix-B.dta, clear
sort ccode_a
merge ccode_a using states2008.1.dta, keep(cabb_a cname_a)
drop if keepobs~=1
drop _merge
sort idnumber
drop if idnumber==idnumber[_n-1]
save Downes-Sechser-Appendix-B.dta, replace

clear
insheet using states2008.1.csv
rename stateabb cabb_b
rename ccode ccode_b
rename statenme cname_b
sort ccode_b
save states2008.1.dta, replace

use Downes-Sechser-Appendix-B.dta, clear
sort ccode_b
merge ccode_b using states2008.1.dta, keep(cabb_b cname_b)
drop if keepobs~=1
drop _merge
sort idnumber
drop if idnumber==idnumber[_n-1]
save Downes-Sechser-Appendix-B.dta, replace


***MERGE WITH POLITY3 DATA (Schultz 2001, pp. 129-30)

clear
insheet using polity3.csv
replace democ = . if democ<0
replace autoc = . if autoc<0
replace xrcomp = . if xrcomp<0
replace parreg = . if parreg<0
rename ccode ccode_a
rename democ democ_a
rename autoc autoc_a
rename xrcomp xrcomp_a
rename parreg parreg_a
sort ccode_a year
save polity3.dta, replace

use Downes-Sechser-Appendix-B.dta, clear
sort ccode_a year
merge ccode_a year using polity3, keep(democ_a autoc_a xrcomp_a parreg_a)
rename democ_a dem_a
rename autoc_a aut_a
drop if keepobs~= 1
drop _merge
save Downes-Sechser-Appendix-B.dta, replace
clear

insheet using polity3.csv
replace democ = . if democ<0
replace autoc = . if autoc<0
replace xrcomp = . if xrcomp<0
replace parreg = . if parreg<0
rename ccode ccode_b
rename democ democ_b
rename autoc autoc_b
rename xrcomp xrcomp_b
rename parreg parreg_b
sort ccode_b year
save polity3.dta, replace

use Downes-Sechser-Appendix-B.dta, clear
sort ccode_b year
merge ccode_b year using polity3, keep(democ_b autoc_b xrcomp_b parreg_b)
rename democ_b dem_b
rename autoc_b aut_b
drop if keepobs~= 1
drop _merge
save Downes-Sechser-Appendix-B.dta, replace

gen polity21_a = dem_a - aut_a + 11
gen polity21_b = dem_b - aut_b + 11


***MERGE WITH MAJOR POWERS DATA (Schultz 2001, p. 264)

gen major_a = 0
*USA
replace major_a = 1 if ccode_a == 2 & year >=1899
*UKG
replace major_a = 1 if ccode_a == 200
*FRN
replace major_a = 1 if ccode_a == 220 & year <= 1940
replace major_a = 1 if ccode_a == 220 & year >= 1945
*GMY
replace major_a = 1 if ccode_a == 255 & year <= 1918
replace major_a = 1 if ccode_a == 255 & year >= 1925 & year <= 1945
replace major_a = 1 if ccode_a == 255 & year >= 1990
*AUH
replace major_a = 1 if ccode_a == 300 & year <= 1918
*ITA
replace major_a = 1 if ccode_a == 325 & year >= 1860 & year<= 1943
*USR
replace major_a = 1 if ccode_a == 365 & year <= 1917
replace major_a = 1 if ccode_a == 365 & year >= 1922
*CHN
replace major_a = 1 if ccode_a == 710 & year >=1950
*JPN
replace major_a = 1 if ccode_a == 740 & year >= 1895 & year<= 1945
replace major_a = 1 if ccode_a == 740 & year >= 1990

gen major_b = 0
*USA
replace major_b = 1 if ccode_b == 2 & year >=1899
*UKG
replace major_b = 1 if ccode_b == 200
*FRN
replace major_b = 1 if ccode_b == 220 & year <= 1940
replace major_b = 1 if ccode_b == 220 & year >= 1945
*GMY
replace major_b = 1 if ccode_b == 255 & year <= 1918
replace major_b = 1 if ccode_b == 255 & year >= 1925 & year <= 1945
replace major_b = 1 if ccode_b == 255 & year >= 1990
*AUH
replace major_b = 1 if ccode_b == 300 & year <= 1918
*ITA
replace major_b = 1 if ccode_b == 325 & year >= 1860 & year<= 1943
*USR
replace major_b = 1 if ccode_b == 365 & year <= 1917
replace major_b = 1 if ccode_b == 365 & year >= 1922
*CHN
replace major_b = 1 if ccode_b == 710 & year >=1950
*JPN
replace major_b = 1 if ccode_b == 740 & year >= 1895 & year<= 1945
replace major_b = 1 if ccode_b == 740 & year >= 1990

save Downes-Sechser-Appendix-B.dta, replace


***MERGE WITH MATERIAL CAPABILITIES DATA (Schultz 2001, 264-65)

clear
insheet using NMC_Raw_2-1a.csv
*CINC scores not included, so need to calculate them by hand
replace milper = . if milper<0
replace milex = . if milex<0
replace energy = . if energy<0
replace irst = . if irst<0
replace upop = . if upop<0
replace tpop = . if tpop<0

gen cincpart1 = .
gen cincpart2 = .
gen cincpart3 = .
gen cincpart4 = .
gen cincpart5 = .
gen cincpart6 = .

local year = 1816
while `year' <= 1993 {
gen milpertotal`year' = .
sum milper if year == `year'
replace milpertotal`year' = r(mean)*r(N)
gen milextotal`year' = .
sum milex if year == `year'
replace milextotal`year' = r(mean)*r(N)
gen energytotal`year' = .
sum energy if year == `year'
replace energytotal`year' = r(mean)*r(N)
gen irsttotal`year' = .
sum irst if year == `year'
replace irsttotal`year' = r(mean)*r(N)
gen upoptotal`year' = .
sum upop if year == `year'
replace upoptotal`year' = r(mean)*r(N)
gen tpoptotal`year' = .
sum tpop if year == `year'
replace tpoptotal`year' = r(mean)*r(N)
replace cincpart1 = (milper/milpertotal`year') if year == `year'
replace cincpart2 = (milex/milextotal`year') if year == `year'
replace cincpart3 = (energy/energytotal`year') if year == `year'
replace cincpart4 = (irst/irsttotal`year') if year == `year'
replace cincpart5 = (upop/upoptotal`year') if year == `year'
replace cincpart6 = (tpop/tpoptotal`year') if year == `year'

local year = `year' + 1
}

egen cinc = rowmean(cincpart1-cincpart6)

drop *total*
drop cincpart*


rename ccode ccode_a
rename cinc cinc_a
sort ccode_a year
save NMC_Raw_2-1a.dta, replace

use Downes-Sechser-Appendix-B.dta, clear
sort ccode_a year
merge ccode_a year using NMC_Raw_2-1a.dta, keep(cinc_a)
drop if keepobs~=1
drop _merge
save Downes-Sechser-Appendix-B.dta, replace

clear
use NMC_Raw_2-1a.dta
rename ccode_a ccode_b
rename cinc_a cinc_b
sort ccode_b year
save NMC_Raw_2-1a.dta, replace

use Downes-Sechser-Appendix-B.dta, clear
sort ccode_b year
merge ccode_b year using NMC_Raw_2-1a.dta, keep(cinc_b)
drop if keepobs~=1
drop _merge
save Downes-Sechser-Appendix-B.dta, replace


***MERGE CONTIGUITY DATA (Schultz 2001, p. 265)

clear
insheet using contdird.csv
rename state1no ccode_a
rename state2no ccode_b
sort ccode_a ccode_b year
save contdird.dta, replace

use Downes-Sechser-Appendix-B.dta, clear
sort ccode_a ccode_b year
merge ccode_a ccode_b year using contdird.dta, keep(conttype)
drop if keepobs~=1
drop _merge
save Downes-Sechser-Appendix-B.dta, replace


***ALLIANCE VARIABLES (Schultz 2001, pp. 265-66)

*Dyadic alliance portfolio similarity
clear
insheet using taudyad.csv
rename ccode1 ccode_a
rename ccode2 ccode_b
rename tau_glob tau_dyad
rename s_un_glo sun_dyad
rename s_wt_glo swt_dyad
sort ccode_a ccode_b year
save taudyad.dta, replace

use Downes-Sechser-Appendix-B.dta, clear
sort ccode_a ccode_b year
merge ccode_a ccode_b year using taudyad.dta, keep(tau_dyad sun_dyad swt_dyad)
lab var tau_dyad "Alliance portfolio similarity (tau)"
lab var sun_dyad "Alliance portfolio similarity (S) - unweighted"
lab var swt_dyad "Alliance portfolio similarity (S) - weighted"
drop if keepobs~=1
drop _merge
save Downes-Sechser-Appendix-B, replace

*Monadic interest similarity with system leader
clear
insheet using tauleader.csv
rename ccode ccode_a
rename tau_lead tauleader_a
rename s_lead swtleader_a
sort ccode_a year
save tauleader.dta, replace

use Downes-Sechser-Appendix-B.dta, clear
sort ccode_a year
merge ccode_a year using tauleader.dta, keep(tauleader_a swtleader_a)
drop if keepobs~=1
drop _merge
save Downes-Sechser-Appendix-B.dta, replace

clear
insheet using tauleader.csv
rename ccode ccode_b
rename tau_lead tauleader_b
rename s_lead swtleader_b
sort ccode_b year
save tauleader.dta, replace

use Downes-Sechser-Appendix-B.dta, clear
sort ccode_b year
merge ccode_b year using tauleader.dta, keep(tauleader_b swtleader_b)
drop if keepobs~=1
drop _merge
lab var tauleader_a "Alliance portfolio similarity with global leader (tau)"
lab var tauleader_b "Alliance portfolio similarity with global leader (tau)"
lab var swtleader_a "Alliance portfolio similarity with global leader (S) - weighted"
lab var swtleader_b "Alliance portfolio similarity with global leader (S) - weighted"
save Downes-Sechser-Appendix-B.dta, replace

clear
insheet using tauleader-unwt.csv
rename ccode ccode_a
rename s_lead sunleader_a
sort ccode_a year
save tauleader-unwt.dta, replace

use Downes-Sechser-Appendix-B.dta, clear
sort ccode_a year
merge ccode_a year using tauleader-unwt.dta, keep(sunleader_a)
drop if keepobs~=1
drop _merge
save Downes-Sechser-Appendix-B.dta, replace

clear
insheet using tauleader-unwt.csv
rename ccode ccode_b
rename s_lead sunleader_b
sort ccode_b year
save tauleader-unwt.dta, replace

use Downes-Sechser-Appendix-B.dta, clear
sort ccode_b year
merge ccode_b year using tauleader-unwt.dta, keep(sunleader_b)
drop if keepobs~=1
drop _merge
lab var sunleader_a "Alliance portfolio similarity with global leader (S) - unweighted"
lab var sunleader_b "Alliance portfolio similarity with global leader (S) - unweighted"
save Downes-Sechser-Appendix-B.dta, replace


***GENERATE VARIABLES USED IN REGRESSIONS

*Major power
gen majmaj = 0
replace majmaj=1 if major_a==1 & major_b==1
gen majmin = 0
replace majmin=1 if major_a == 1 & major_b == 0
gen minmaj = 0
replace minmaj=1 if major_a == 0 & major_b == 1

*Capabilities
*Proportion of dyadic capabilities (Schultz 2001, p. 264-65)
gen capshare_a = cinc_a/(cinc_a + cinc_b)

*Contiguity
*Separated by 150 miles of water or less (Schultz 2001, p. 265)
gen contig = 0
replace contig = 1 if conttype<=4

*Revision types (Schultz 2001, pp. 143-44)
gen territory = 0
gen policy = 0
gen government = 0
gen other = 0
replace territory = 1 if revtype==1
replace policy = 1 if revtype==2
replace government = 1 if revtype==3
replace other = 1 if revtype==4

*World war years (Schultz 2001, p. 134)
gen worldwar=0
replace worldwar=1 if (year>=1939 & year<=1945) | (year>=1914 & year<=1918)
local counter = 1914
while `counter' <= 1918 {
gen dummy`counter' = 0
replace dummy`counter' = 1 if year == `counter'
local counter = `counter' + 1
}
local counter = 1939
while `counter' <= 1945 {
gen dummy`counter' = 0
replace dummy`counter' = 1 if year == `counter'
local counter = `counter' + 1
}

*Democracy (Schultz 2001, p. 129, n.4)
gen democ_a = 0
replace democ_a = 1 if (xrcomp_a == 2 | xrcomp_a == 3) & (parreg_a == 2 | parreg_a == 5)
replace democ_a = . if xrcomp_a == . | parreg_a == .

gen democ_b = 0
replace democ_b = 1 if (xrcomp_b == 2 | xrcomp_b == 3) & (parreg_b == 2 | parreg_b == 5)
replace democ_b = . if xrcomp_b == . | parreg_b == .

gen demdem = 0
replace demdem = 1 if democ_a == 1 & democ_b == 1


***IDENTIFY 25 MOST INFLUENTIAL DEMOCRATIC VICTORIES

*Model 4 (Schultz 2001, pp. 146-47)
*Regressions include only cases from 1816-1984 due to missing data (Schultz 2001, p. 126)

*Modified replication (use tau for dyadic alliance portfolio similarity and weighted S-scores for status quo evaluation)
*Note that we do not generate leverage statistics for this regression; see Appendix B.
logit recip democ_a democ_b demdem majmaj majmin minmaj capshare_a contig tau_dyad swtleader_a swtleader_b territory government policy other if worldwar==0 & year<=1984

*Verbatim replication
logit recip democ_a democ_b demdem majmaj majmin minmaj capshare_a contig swt_dyad tauleader_a tauleader_b territory government policy other if worldwar==0 & year<=1984

ldfbeta democ_a
rename DFdemoc_ dfdemoc_a

*Identify the top 25 democratic victories
gsort +dfdemoc_a
list idnumber cname_a cname_b startyear dfdemoc_a if democ_a == 1 & recip == 0 & e(sample) & _n<=26

save Downes-Sechser-Appendix-B.dta, replace
